package com.leyou.common.advice;

import com.leyou.common.exception.ExceptionResult;
import com.leyou.common.exception.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 公共处理异常的对象： Advice
 */
@ControllerAdvice
public class ExceptionHandlerController {

    /**
     * 只要出现LyException就会进入这个方法中
     * @param e
     * @return
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> excetion(LyException e){
        return ResponseEntity
                .status(e.getStatus())//指定状态码
                .body(new ExceptionResult(e)); //指定响应体
    }
}
